package com.bjxst;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;

/**数据输入流
 * 作用：读取基于数据输出流向文件当中所写出的那些数据，通过数据输入流可以
 * 把这些数据按照相应的类型，读取到我们程序当中*/
public class DataInputStreamDemo {
    public static void main(String[] args) {
        DataInputStream dis = null;
        try {
            dis = new DataInputStream(new BufferedInputStream(new FileInputStream("d:/data.txt")));
            //直接读取数据，注意：读取的顺序要与写入的顺序一致
            System.out.println("char:"+dis.readChar());
            System.out.println("int:"+dis.readInt());
            System.out.println("Double:"+dis.readDouble());
            System.out.println("boolean:"+dis.readBoolean());
            System.out.println("String:"+dis.readUTF());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
           try{
               if(dis != null)dis.close();
           }catch (Exception e){
               e.printStackTrace();
           }
        }
    }
}
